package com.bsj.travel.security.auth;

import com.bsj.travel.security.annotation.RequiresPermissions;
import com.bsj.travel.security.annotation.RequiresRoles;
import com.bsj.travel.def.common.VO.TokenUser;

/**
 * @author yinhao
 * @version 1.0
 * @description Token 权限验证工具类
 * @date 2024/1/10
 */
public class AuthUtil {

    public static AuthLogic authLogic = new AuthLogic();

    /**
     * 会话注销
     */
    public static void logout() {
        authLogic.logout();
    }

    /**
     * 校验当前会话是否已经登录，如未登录，则抛出异常
     */
    public static void checkLogin() {
        authLogic.checkLogin();
    }

    /**
     * 获取当前请求的登录用户信息
     * @return
     */
    public static TokenUser getLoginUser() {
        return authLogic.getLoginUser();
    }

    /**
     * 根据注解传入参数鉴权
     * @param requiresRoles 角色权限注解
     */
    public static void checkRole(RequiresRoles requiresRoles) {
        authLogic.checkRole(requiresRoles);
    }

    /**
     * 根据注解进行参数鉴权，验证未通过则抛出异常
     * @param requiresPermissions
     */
    public static void checkPerm(RequiresPermissions requiresPermissions) {
        authLogic.checkPerm(requiresPermissions);
    }
}
